package org.dgt.service.api.impl;

import java.util.List;

import org.dgt.dao.PersistenceManagerHibernate;
import org.dgt.model.core.Product;
import org.dgt.model.core.ProductPriceUserRegistry;
import org.dgt.model.core.UserInformation;
import org.dgt.service.api.UserService;
import org.springframework.dao.DataAccessException;

public class UserServiceImpl implements UserService {

	private final boolean SELLER = true;
	private PersistenceManagerHibernate persistenceManager; 

	public void setPersistenceManager(PersistenceManagerHibernate persistenceManager) {
		this.persistenceManager = persistenceManager;
	}

	public UserInformation getUserById(Long userId) {
		return persistenceManager.findById(UserInformation.class, userId);
	}

	public boolean registerProductToSell(Long userId, Long productId,
			float price, int quantity, String notification) {
		try{
			ProductPriceUserRegistry reg = new ProductPriceUserRegistry();
			reg.setUserInfo(persistenceManager.findById(UserInformation.class, userId));
			reg.setProduct(persistenceManager.findById(Product.class, productId));
			reg.setPriceRegistry(price);
			reg.setQuantity(quantity);
			reg.setSellerOrBuyer(SELLER);
			reg.setNotificationBy(notification);
			persistenceManager.saveOrUpdate(reg);
			return true;
		}
		catch(DataAccessException e){
			e.printStackTrace();
			return false;
		}
	}



	public List getRegisterProductsToSell(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}



	public boolean registerProductToBuy(Long userId, Long productId,
			float price, int quantity) {
		// TODO Auto-generated method stub
		return false;
	}



	public List getRegisterProductsToBuy(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}



	public boolean updatePriceToSell(Long userId, Long productId, float newPrice) {
		// TODO Auto-generated method stub
		return false;
	}



	public boolean updateQuantityToSell(Long userId, Long productId, int quantity) {
		// TODO Auto-generated method stub
		return false;
	}



	public boolean isUserHaveRight(Long userId, String right) {
		// TODO Auto-generated method stub
		return false;
	}



	public boolean isUserLogin(Long userId) {
		// TODO Auto-generated method stub
		return false;
	}



	public UserInformation getCurrentUser() {
		// TODO Auto-generated method stub
		return null;
	}


}
